﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Blockey
{
    public class Material
    {
        public virtual void SetEffectParameters(Effect effect)
        {
            // DOES NOTHING! MUAHAHAHAHAH
        }
    }

    public class LightingMaterial : Material
    {
        public Vector3 AmbientColor { get; set; }
        public Vector3 LightDirection { get; set; }
        public Vector3 LightColor { get; set; }
        public Vector3 SpecularColor { get; set; }

        public LightingMaterial()
        {
            AmbientColor = new Vector3(0.1f, 0.1f, 0.1f);
            LightDirection = new Vector3(1, 1, 1);
            LightColor = new Vector3(0.9f, 0.9f, 0.9f);
            SpecularColor = new Vector3(1, 1, 1);
        }

        public override void SetEffectParameters(Effect effect)
        {
            if (effect.Parameters["AmbientColor"] != null)
                effect.Parameters["AmbientColor"].SetValue(AmbientColor);
            if (effect.Parameters["LightDirection"] != null)
                effect.Parameters["LightDirection"].SetValue(AmbientColor);
            if (effect.Parameters["LightColor"] != null)
                effect.Parameters["LightColor"].SetValue(AmbientColor);
            if (effect.Parameters["SpecularColor"] != null)
                effect.Parameters["SpecularColor"].SetValue(AmbientColor);
        }
    }

    public class PointLightMaterial : Material
    {
        public Vector3 AmbientLightColor { get; set; }
        public Vector3 AmbientColor { get; set; }
        public Vector3 LightPosition { get; set; }
        public Vector3 LightColor { get; set; }
        public float LightAttenuation { get; set; }
        public float LightFalloff { get; set; }
        //public Vector3 SpecularColor { get; set; }
        //public float SpecularPower { get; set; }
        //public Vector3 DiffuseColor { get; set; }

        public PointLightMaterial()
        {
            AmbientLightColor = new Vector3(0.15f, 0.15f, 0.15f);
            AmbientColor = new Vector3(0.1f, 0.1f, 0.1f);
            LightPosition = new Vector3(0, 0, 0);
            LightColor = new Vector3(0.85f, 0.85f, 0.85f);
            LightAttenuation = 5000;
            LightFalloff = 2;
            //DiffuseColor = Vector3.One;
            //SpecularColor = Vector3.One;
            //SpecularPower = 32;
        }

        public override void SetEffectParameters(Effect effect)
        {
            if (effect.Parameters["AmbientLightColor"] != null)
                effect.Parameters["AmbientLightColor"].SetValue(AmbientLightColor);
            if (effect.Parameters["LightPosition"] != null)
                effect.Parameters["LightPosition"].SetValue(LightPosition);
            if (effect.Parameters["LightColor"] != null)
                effect.Parameters["LightColor"].SetValue(LightColor);
            if (effect.Parameters["LightAttenuation"] != null)
                effect.Parameters["LightAttenuation"].SetValue(LightAttenuation);
            if (effect.Parameters["LightFalloff"] != null)
                effect.Parameters["LightFalloff"].SetValue(LightFalloff);

            //if (effect.Parameters["DiffuseColor"] != null)
            //    effect.Parameters["DiffuseColor"].SetValue(DiffuseColor);
            if (effect.Parameters["AmbientColor"] != null)
                effect.Parameters["AmbientColor"].SetValue(AmbientColor);
            
            //if (effect.Parameters["SpecularPower"] != null)
            //    effect.Parameters["SpecularPower"].SetValue(SpecularPower);
            //if (effect.Parameters["SpecularColor"] != null)
            //    effect.Parameters["SpecularColor"].SetValue(SpecularColor);
        }
    }

}
